home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tsptp.zip / ACKERMAN.PAS next >
Pascal/Delphi Source File  |  1993-04-09  |  3KB  |  92 lines

  1. (******************************************************************************)
  2. (*                                  ACK.PAS                                   *)
  3. (* Ackermann benchmark See 'Software Practice and Experince', Vol 7 pp317-329 *)
  4. (* (1977)                                                                     *)
  5. (******************************************************************************)
  6.  
  7. PROGRAM ACKERMAN(Output);
  8.  
  9. (******************************************************************************)
  10. (*                                TIMING                                      *)
  11. (******************************************************************************)
  12.  
  13. (*$IFNDEF TopSpeed *)
  14.  (*%F TRUE   *** Compile for Turbo Pascal ***)
  15.   USES TPBench;
  16.  (*%E*)
  17. (*$ELSE     *** Compile for TopSpeed Pascal ***)
  18.   IMPORT TSBench *;
  19. (*$ENDIF *)
  20.  
  21. (******************************************************************************)
  22.  
  23.   VAR Failed: BOOLEAN;
  24.  
  25.   FUNCTION Ackermann(m, n: BmInt): BmInt;
  26.   BEGIN
  27.     IF m = 0 THEN
  28.       Ackermann := n + 1
  29.     ELSE IF n = 0 THEN
  30.       Ackermann := Ackermann(m - 1, 1)
  31.     ELSE
  32.       Ackermann := Ackermann(m - 1, Ackermann(m, n - 1));
  33.   END;
  34.  
  35.   PROCEDURE Ack;
  36.     VAR i, j, k, k1: BmInt;
  37.   BEGIN
  38.     k := 16;
  39.     k1 := 1;
  40.     Failed := FALSE;
  41.     FOR i := 1 TO 6 DO
  42.     BEGIN
  43.       j := Ackermann( 3, i);
  44.       IF j <> k - 3 THEN
  45.         Failed := TRUE;
  46.  
  47. (*** The following lines should only be uncommented for debugging.
  48.  
  49.       WriteLn(' NO OF CALLS: ', (512.0 * FLOAT(k1) - 15.0 * FLOAT(k)
  50.                  + 9.0 * FLOAT(i) + 37.0)/3.0, 15);
  51. ***)
  52.       k1 := 4 * k1;
  53.       k  := 2 * k;
  54.     END;
  55.  
  56.   END;
  57.  
  58. BEGIN
  59.   WriteLn('Ackermann Benchmark');
  60.  
  61. (******************************************************************************)
  62. (*  Compute the looping overhead.  The Dummy procedure must have some side-   *)
  63. (*  effect so that it is not optimised out of existence.                      *)
  64. (******************************************************************************)
  65.  
  66.   StartTimer;                                   (* Start the clock.           *)
  67.  
  68.   REPEAT
  69.     Dummy;
  70.   UNTIL NullTimesUp;
  71.  
  72. (******************************************************************************)
  73. (*  Now run the benchmark.  Note that the Dummy procedure is also called so   *)
  74. (*  that we can eliminate its overhead from the looping overhead.             *)
  75. (******************************************************************************)
  76.  
  77.   StartTimer;                                   (* Start the clock.           *)
  78.  
  79.   REPEAT
  80.     Ack;
  81.     Dummy
  82.   UNTIL BenchTimesUp;
  83.  
  84. (******************************************************************************)
  85.  
  86.   ReportTimes;
  87.  
  88.   IF Failed THEN
  89.     WriteLn('Fail')
  90.   ELSE
  91.     WriteLn('Pass');
  92. END.